package com.Service;

import com.Dao.SubjectDao;
import com.POJO.Subject;
import com.Service.Imp.SubjectServiceImp;
import com.Utils.R;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;
import java.util.Map;

@Service
public class SubjectService extends ServiceImpl<SubjectDao, Subject> implements SubjectServiceImp {
    @Autowired
    private SubjectDao subjectDao;
    public List<Subject> HomeFind(){
        QueryWrapper<Subject> subjectQueryWrapper=new QueryWrapper<>();
        subjectQueryWrapper.groupBy("subject1").last("limit 11");
        return subjectDao.selectList(subjectQueryWrapper);
    }
    public List<Subject> ListFind(){
        QueryWrapper<Subject> subjectQueryWrapper=new QueryWrapper<>();
        return subjectDao.selectList(subjectQueryWrapper);
    }
    public int addSubject(String subject1,String subject2,String subject3){
        Subject subject=new Subject();
        subject.setSubject1(subject1);
        subject.setSubject2(subject2);
        subject.setSubject3(subject3);
        return subjectDao.insert(subject);
    }
    public int updataSubject(int id,String subject1,String subject2,String subject3){
        Subject subject=new Subject();
        UpdateWrapper<Subject> updateWrapper=new UpdateWrapper<>();
        updateWrapper.set("subject1",subject1);
        updateWrapper.set("subject2",subject2);
        updateWrapper.set("subject3",subject3);
        updateWrapper.eq("id",id);
        return subjectDao.update(subject,updateWrapper);
    }
    public int delSubject(int id){
        QueryWrapper<Subject> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("id",id);
        return subjectDao.delete(queryWrapper);
    }
}
